import { Component, OnInit, ViewChild } from '@angular/core';
import { Router, ActivatedRoute } from "@angular/router"; //路由引入
import { JsonApiService } from "app/core/api/json-api.service";
import { config } from '../../shared/smartadmin.config';

declare var $: any;
@Component({
    selector: 'sa-project-docking-config',
    templateUrl: './project-docking-config.component.html',
    styleUrls: ['./project-docking-config.component.css']
})
export class ProjectDockingConfigComponent implements OnInit {
    tableData: any = []; // table的表单数据
    totalCounts: number = 0; //分页总条数
    curPage: number = 1; //分页当前页
    pageSize: number = 10; //内置的分页每页条数
    activeSelected: string = ''; //row高亮
    // 查询参数
    selectedDeviceId: any = ""; // 选中的设备ID
    selectedCarNumber: any = ""; // 选中的车牌号
    userName: any = ""; // 操作人
    searchKey: any = ""; // 用户的搜索关键字
    tableSearchParam:any = {
        companyId: '',
        companyName: '',
        roleId: '',
        roleName: '',
        type: '',
        startTime: '',
        endTime: ''
//      searchKey: ''
    }
    paramFormat:any = {
        id:'id',
        text:'name',
    }
    dataURL:string = "role/roleList.html";
    constructor(private router: Router, private activatedRoute: ActivatedRoute, private jsonApiService: JsonApiService) {
        activatedRoute.queryParams.subscribe(queryParams => {
        });
    }
    ngOnInit() {
        // this.load();
    }
    //公司[项目]选中回调
    companySelected(data) {
        this.tableSearchParam.companyId = data.companyId;
        this.tableSearchParam.companyName = data.companyName;
        this.tableSearchParam.deviceId = data.deviceId;
        this.tableSearchParam.carNumber = data.carNumber;
    }
    //角色选中
    optionSelected(data){
        this.tableSearchParam.roleId = data.id;
        this.tableSearchParam.roleName = data.text;
    }
    // 时间选择回调
    dateSelect(time) {
        this.tableSearchParam.startTime = time.startTime;
        this.tableSearchParam.endTime = time.endTime;
        this.tableSearch();
    }
    
    // 获取列表数据
    load() {
        let param = {
            "pageSize": this.pageSize,
            "nowPage": this.curPage,
            "parameters": {
                companyId: this.tableSearchParam.companyId,
                roleId: this.tableSearchParam.roleId,
                type: this.tableSearchParam.type,
                carNumber: this.tableSearchParam.carNumber,
                searchKey: common.stringTrim(this.searchKey),
                startTime: this.tableSearchParam.startTime,
                endTime: this.tableSearchParam.endTime,
                export:'',
            }
        }
        let reqdata = 'gridPager=' + JSON.stringify(param);
        this.jsonApiService.http("projectDocking/projectDockingConfigLogList.html", reqdata).subscribe(result => {
//          let data = []
            if (result.isSuccess && result.exhibitDatas) {
//              data = result.exhibitDatas
//              // 将类型进行映射
//              for (let i = 0; i < result.exhibitDatas.length; i++) {
//                  result.exhibitDatas[i].typeStr = this.eventObj[result.exhibitDatas[i].type]
//              }
                this.tableData = result.exhibitDatas
                this.totalCounts = result.recordCount;
            }
        });
    }

    // 分页回调
    paginate(e) {
        this.activeSelected = '';
        this.curPage = e.page + 1;
        this.pageSize = e.rows;
        this.load();
    }
    // 刷新表
    refresh() {
        this.load();
    }
    // 表单查询
    tableSearch() {
        this.curPage = 1;
        this.load();
    }

    // 数据导出
	exportData(){
	    let param = {
	        "pageSize": this.pageSize,
            "nowPage": this.curPage,
            "parameters": {
                companyId: this.tableSearchParam.companyId,
                roleId: this.tableSearchParam.roleId,
                type: this.tableSearchParam.type,
                carNumber: this.tableSearchParam.carNumber,
                searchKey: common.stringTrim(this.searchKey),
                startTime: this.tableSearchParam.startTime,
                endTime: this.tableSearchParam.endTime,
                export:'1',
            }
        }
        let timeCheck = common.correctTime(param.parameters, ['export'])
		if(!timeCheck.status){
			this.jsonApiService.message(timeCheck.message);
			return;
		}
        common.exprotDataFile(param, 'gridPager', config.BaseURL + 'projectDocking/projectDockingConfigLogList.html')		
    }
}   